package com.leyou.controller;

import java.util.List;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import com.leyou.api.R;
import com.leyou.common.page.PageResult;
import com.leyou.vo.BrandSaveParamVo;
import com.leyou.vo.BreadPageParamVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.leyou.entity.BrandEntity;
import com.leyou.service.BrandService;
/**
 * 品牌表，一个品牌下有多个商品（spu），一对多关系
 *
 * @author Daifeng
 * @email 2661184062@qq.com
 * @date 2020-12-25 16:44:48
 */
@RestController
@RequestMapping("/brand")
public class BrandController {

    @Autowired
    private BrandService brandService;


    @GetMapping("/cid/{cid}")
    public R getBrandByCategoyId(@PathVariable Long cid) {
      List<BrandEntity>  list = brandService.getBrandByCategoyId(cid);
      if(list != null && list.size() >0){
          return R.ok().put("data",list);
      }else {
          return R.error().put("key","该分类暂无品牌信息");
      }
    }

    @GetMapping("/page")
    public R setBrandServic(BreadPageParamVo paramVo) {
        // 添加分页条件
        PageResult<BrandEntity> pages =  brandService.getBrandPages(paramVo);

        return  R.ok().put("data",pages);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R getBreadInfoById(@PathVariable("id") Long id){
		BrandEntity brand = brandService.getById(id);
        return R.ok().put("brand", brand);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@RequestBody BrandSaveParamVo brand){
		brandService.SaveBatchCategory(brand);
        return R.ok();

    }

    /**
     * 修改
     */
    @PutMapping("/save")
    public R update(@RequestBody BrandSaveParamVo brand){
		brandService.updateBatchCategory(brand);
        return R.ok();

    }

    /**
     * 删除
     */
    @DeleteMapping("/delete/{id}")
    public R delete(@PathVariable Long id){
		brandService.deleteById(id);
        return R.ok();
    }

}
